package com.example.contactbackend.wzh.controller;

import com.example.contactbackend.wzh.mapper.UserMapper;
import com.example.contactbackend.wzh.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/getallusers")
    public List<User> getAllUsers() {
        List<User> contacts = userMapper.getAllUsers();
        return contacts;
    }

    @PostMapping("/adduser")
    public String addUser(User user) {
        if(userMapper.addUser(user) == 1)
            return "yes";
        else
            return "no";
    }

    @PostMapping("/delete")
    public String deleteUserById(int id) {
        if(userMapper.deleteUserById(id) == 1)
            return "yes";
        else
            return "no";
    }

    @PostMapping("/update")
    public String updateUserById(User user) {
        if(userMapper.updateUserById(user) == 1)
            return "yes";
        else
            return "no";
    }
}
